<?php
session_start();//start the session

class Friends extends Controller
{

	function Intro()
		{
			parent::Controller();
		}//end method

	function index()
		{
			$this->view();
		}//end method

		
	function view()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;

			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else//if authentication succeed
				{
					$data	= array();
					$data	= $datas;

					if($this->uri->segment(3)!='')
						$friendId	= $this->uri->segment(3);
					else
						$friendId	= $userId;
					$data['view_friends']	= true;
					$data['user_id']		= $userId;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);
				
					//$totFriends	= getTotRec("friend_id","friends_list","user_id='$friendId' AND approved_status='yes'");
					$friendsList	= $this->common->getFriends($friendId);
					if(count($friendsList)>0)
						//if the user have more than one friends
						//call function to list all friends
						$data['friends_list']	= $this->listFriends($friendId);
					else
						{
							//this part to show no friends found message
							if($userId==$friendId)
								$title	= "У вас ";
							else
								{
									$curUsrRs	= getRow("users","firstname, lastname","user_id='$friendId'");
									$title		= ''.$usrRs['firstname'].' '.$usrRs['lastname'].''." має ";
								}
							$data['friends_list']	= '<div class="page_header">Мої друзі (0)</div><div>Наразі тут показані всі ваші друзі</div><br /><br /><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="splborder2"><tr height="100"><td align="center"><b>'.$title.' немає жодного друга. Скористайтесь пошуком, щоб додати нових друзів! </b></td></tr></table>';
						}


					$rs		= getRow("users","email","user_id='$userId'");
					$data['invite_from_address']	= $rs['email'];
					$this->smartyextended->view('friends',$data);
				}
		}//end view()


	function listFriends($friendId)
		{
			$this->load_settings();
			global $userId,$now;
			$siteVars	= $this->common->getSiteVars();
			$recPerPage	= $siteVars['recordsPerPage'];

			//$res	= mysql_query("SELECT DISTINCT friend_id FROM friends_list WHERE user_id='$friendId' AND approved_status='yes' LIMIT 0,".$recPerPage);
			$res	= mysql_query("SELECT friend_id AS friend_id FROM `friends_list` WHERE user_id='$friendId' and approved_status='yes'
						UNION
						SELECT user_id as friend_id FROM `friends_list` WHERE friend_id='$friendId' and approved_status='yes'");

			$i		= 0;
			if($res)
			while($rs = mysql_fetch_object($res))
				{
					$i++;
					$usrRs		= getRow("users", "firstname, lastname", "user_id='$rs->friend_id'");
					$avatar		= $this->common->getAvatar($rs->friend_id);
					$username	= ''.$usrRs['firstname'].' '.$usrRs['lastname'].'';
					$viewUrl	= base_url()."friends/view/".$rs->friend_id;
					$sendUrl	= base_url()."messages/compose/".$rs->friend_id;
					$removeUrl	= base_url()."friends/remove/".$rs->friend_id;
					$addUrl		= base_url()."friends/add/".$rs->friend_id;
					$profileUrl = base_url()."user/profile/".$rs->friend_id;
					//prepares actions
					if($friendId==$userId)//if friends list for current user
						{
							if($rs->friend_id==$userId)
								$actionContent	=	'<div><a href="'.$viewUrl.'">Переглянути друзів</a></div>';
							else
								$actionContent	=	'<div><a href="'.$sendUrl.'">Надіслати повідомлення</a></div>
													 <div><a href="'.$viewUrl.'">Переглянути друзів</a></div>
													 <div><a href="'.$removeUrl.'">Видалити з друзів</a></div>';

							$content	.=	' 
											<div class="friends_result" style="width: 356px; float: left; ">
											<table cellpadding="0" cellspacing="0">
											<tr>
											<td class="friends_result0"><div class="list2"><span><div><a href= '.$profileUrl.'><img src="'.$avatar.'" border="0"></a></div></span></div></td>
											<td class="friends_result1" width="100%" valign="top" style="padding:10px; padding-left:0;">
											  <div class="friends_name"><a href="'.$profileUrl.'">'.$username.'</a></div>
											  '.$this->common->offline($rs->friend_id, 'friends').'
											</td>
											<td class="friends_result2" valign="top" nowrap="nowrap">'.$actionContent.'</td>
											</tr>
											</table>
											</div>
											';
						}
					else//elseif friends list for other users
						{
							if($rs->friend_id==$userId)
								$actionContent	=	'<div><a href="'.$viewUrl.'">Переглянути друзів</a></div>';
							else
								{
									$isUrFriend		= getTotRec("friends_list_id","friends_list","user_id='$userId' AND friend_id='$rs->friend_id'");
									if($isUrFriend>0)
										$add2friends	= '';
									else
										$add2friends	= '<div><a href="'.$addUrl.'">Додати до друзів</a></div>';
									$actionContent		= '<div><a href="'.$sendUrl.'">Надіслати повідомлення</a></div>
														   <div><a href="'.$viewUrl.'">Переглянути друзів</a></div>
														   '.$add2friends;
								}

							$content	.=	' 
											<div class="friends_result" style="width: 356px; height: 100px; float: left; ">
											<table cellpadding="0" cellspacing="0">
											<tr>
											<td class="friends_result0"><div class="list2"><span><div><a href= '.$profileUrl.'><img src="'.$avatar.'" border="0"></a></div></span></div></td>
											<td class="friends_result1" width="100%" valign="top" style="padding:10px; padding-left:0;">
											  <div class="friends_name"><a href="'.$profileUrl.'">'.$username.'</a></div>
											  '.$this->common->offline($rs->friend_id, 'friends').'
											</td>
											<td class="friends_result2" valign="top" nowrap="nowrap">'.$actionContent.'</td>
											</tr>
											</table>
											</div>
											';
						}//end else
				}//end while

			//prepares total list
			if($userId==$friendId)
				$title	= "Мої друзі (";
			else
				{
					$curUsrRs	= getRow("users","firstname, lastname","user_id='$friendId'");
					$title		= 'Друзі &rarr; '.$curUsrRs['firstname'].' '.$curUsrRs['lastname'].' (';
				}
			$content	=	'<div class="page_header">'.$title.$i.')</div><div>Наразі тут показані всі друзі <b>'.$curUsrRs['firstname'].' '.$curUsrRs['lastname'].'</b></div><br /><br />'.$content;
			return $content;
		}//end listFriends()

	function remove()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;

			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else//if authentication succeed
				{
					$data	= array();
					$data	= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					
					$friendId	= $this->uri->segment(3);
					$usrRs		= getRow("users","firstname, lastname","user_id='$friendId'");
					if($_POST['remove'])
						{
							mysql_query("DELETE FROM friends_list WHERE user_id='$userId' AND friend_id='$friendId'");
							mysql_query("DELETE FROM friends_list WHERE user_id='$friendId' AND friend_id='$userId'");
							redirect('friends/view/'.$userId, 'refresh');
						}
					else
						{
							$data['remove_friend']	= true;
							$data['friend_id']		= $friendId;
							$data['friend_name']	= ''.$usrRs['firstname'].' '.$usrRs['lastname'].'';
							$data['user_id']		= $userId;
							$data['user_avatar']	= $this->common->getAvatar($friendId);		//function which returns the avatar of the given userid
							
							$this->smartyextended->view('friends',$data);
						}
				}
		}//end remove()

	function confirm()
		{
			$this->load_settings();
			$datas	= $this->common->basicvars();
			global $userId,$now;
			
			$friendId	= $this->uri->segment(3);
			$friendName	= $this->common->getUsername($friendId);
			updateRecords("friends_list","approved_status='yes'","friend_id='$userId' AND user_id='$friendId'");
			insertRecord("friends_list","user_id='$userId', friend_id='$friendId',datestamp='$now', approved_status='yes'");

			redirect('friends/newest/', 'refresh');

		}//end confirm()

		//відхилення запиту на дружбу
	function reject()
		{
			$this->load_settings();
			$datas	= $this->common->basicvars();
			global $userId,$now;

			$friendId	= $this->uri->segment(3);
			mysql_query("DELETE FROM friends_list WHERE friend_id='$userId' AND user_id='$friendId'");
			mysql_query("DELETE FROM friends_list WHERE user_id='$userId' AND friend_id='$friendId'");
			redirect('friends/request/', 'refresh');

		}//end reject()
		
				//відхилення запиту на дружбу
	function rejectout()
		{
			$this->load_settings();
			$datas	= $this->common->basicvars();
			global $userId,$now;

			$friendId	= $this->uri->segment(3);
			mysql_query("DELETE FROM friends_list WHERE friend_id='$userId' AND user_id='$friendId'");
			mysql_query("DELETE FROM friends_list WHERE user_id='$userId' AND friend_id='$friendId'");
			redirect('friends/outrequest/', 'refresh');

		}//end reject()
/*
	function deleteallfuck()
		{
			$this->load_settings();
			$datas	= $this->common->basicvars();
			global $userId,$now;

			for ($i = 3112; $i < 157622; $i++) {
			echo "DELETE FROM `users` WHERE user_id='$i'".'<br>';
			mysql_query("DELETE FROM `users` WHERE user_id='$i'");
			}

		}//end reject()
*/		

//додати нового друга
	function add()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;

			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else//if authentication succeed
				{
					$data	= array();
					$data	= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					
					$friendId	= $this->uri->segment(3);
					$usrRs		= getRow("users","firstname, lastname","user_id='$friendId'");

					$data['add_friend']		= true;
					$data['friend_id']		= $friendId;
					$data['friend_name']	= ''.$usrRs['firstname'].' '.$usrRs['lastname'].'';
					$data['user_id']		= $userId;
					$data['user_avatar']	= $this->common->getAvatar($friendId);		//function which returns the avatar of the given userid
					$this->smartyextended->view('friends',$data);
				}
		}//end add()

		//вхідні запити на дружбу
	function request()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;

			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else//if authentication succeed
				{
					$data	= array();
					$data	= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					$data['show_request']	= true;
					$data['request_content']= $this->getRequestList();
					$this->smartyextended->view('friends',$data);
				}
		}//end request()

	function outrequest()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;

			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else//if authentication succeed
				{
					$data	= array();
					$data	= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					$data['show_outrequest']	= true;
					$data['outrequest_content']= $this->getOutRequestList();
					$this->smartyextended->view('friends',$data);
				}
		}//end request()
		
		
	function phonebook()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;

			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else//if authentication succeed
				{
					$data	= array();
					$data	= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					$data['show_phonebook']	= true;
					$data['phonebook_content']= $this->PhoneBookNumbers($userId);
					$this->smartyextended->view('friends',$data);
				}
		}//end request()
		
	function newest()
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;

			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else//if authentication succeed
				{
					$data	= array();
					$data	= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					$data['show_newestadd']	= true;
					$data['newestadd_content']= $this->NewestAddFriends($userId);
					$this->smartyextended->view('friends',$data);
				}
		}//end request()

	function NewestAddFriends($friendId)
		{
			$this->load_settings();
			global $userId,$now;
			$siteVars	= $this->common->getSiteVars();

			//$res	= mysql_query("SELECT DISTINCT friend_id FROM friends_list WHERE user_id='$friendId' AND approved_status='yes' LIMIT 0,".$recPerPage);
			$res	= mysql_query("SELECT friend_id AS friend_id, datestamp AS datestamp FROM `friends_list` WHERE user_id='$friendId' and approved_status='yes' ORDER BY datestamp DESC");

			if($res)
			while($rs = mysql_fetch_object($res))
				{
					$i++;
					$usrRs		= getRow("users", "firstname, lastname", "user_id='$rs->friend_id'");
					$avatar		= $this->common->getAvatar($rs->friend_id);
					$username	= ''.$usrRs['firstname'].' '.$usrRs['lastname'].'';
					$viewUrl	= base_url()."friends/view/".$rs->friend_id;
					$sendUrl	= base_url()."messages/compose/".$rs->friend_id;
					$removeUrl	= base_url()."friends/remove/".$rs->friend_id;
					$addUrl		= base_url()."friends/add/".$rs->friend_id;
					$profileUrl = base_url()."user/profile/".$rs->friend_id;
					//prepares actions


							$actionContent	=	'<div><a href="'.$sendUrl.'">Надіслати повідомлення</a></div>
													 <div><a href="'.$viewUrl.'">Переглянути друзів</a></div>
													 <div><a href="'.$removeUrl.'">Видалити з друзів</a></div>';

							$content	.=	' 
											<div class="friends_result" style="width: 356px; height: 100px; float: left; ">
											<table cellpadding="0" cellspacing="0">
											<tr>
											<td class="friends_result0"><div class="list2"><span><div><a href= '.$profileUrl.'><img src="'.$avatar.'" border="0"></a></div></span></div></td>
											<td class="friends_result1" width="100%" valign="top" style="padding:10px; padding-left:0;">
											  <div class="friends_name"><a href="'.$profileUrl.'">'.$username.'</a></div>
											  '.$this->common->offline($rs->friend_id, 'friends').'
											</td>
											<td class="friends_result2" valign="top" nowrap="nowrap">'.$actionContent.'</td>
											</tr>
											</table>
											</div>
											';

				}//end while

			//prepares total list

			return $content;
		}//end listFriends()
		
		
	function PhoneBookNumbers($friendId)
		{
			$this->load_settings();
			global $userId,$now;
			
			$query	= "SELECT 
						friends_list.friend_id AS friend_id, contact_profile.mobile AS mobile, contact_profile.land_line AS land_line 
						FROM friends_list, contact_profile 
						WHERE friends_list.user_id = '$friendId' and friends_list.approved_status='yes' 
						and contact_profile.user_id = friends_list.friend_id";
			$res	= mysql_query($query);

			if($res)
			while($rs=mysql_fetch_object($res))
				{
					$usrRs		= getRow("users", "firstname, lastname", "user_id='$rs->friend_id'");
					$username	= ''.$usrRs['firstname'].' '.$usrRs['lastname'].'';
					$avatar		= $this->common->getAvatar($rs->friend_id);

					$profileUrl = base_url()."user/profile/".$rs->friend_id;
					//prepares actions
						
						if ($rs->mobile!='' or $rs->land_line!='') {
							$content	.=	'
											<div style="float: left;">
											<table cellpadding="0" cellspacing="0">
											<tr>
											<td width="78"><div class="list2"><span><div><a href= '.$profileUrl.'><img src="'.$avatar.'" border="0"></a></div></span></div></td>
											<td>
											<div class="phonebook" style="width: 259px;  padding:10px; margin-right: 10px;">
											<table cellpadding="0" cellspacing="0">
											<tr>
											<tr><td style="padding-right: 10px;" valign="top" nowrap="nowrap" class="fieldphone">Ім’я: 		  </td> <td><a href="'.$profileUrl.'">'.$username.'</a></td></tr>
											<tr><td style="padding-right: 10px;" valign="top" nowrap="nowrap" class="fieldphone">Моб. телефон: </td> <td>'.$rs->mobile.'</td></tr>
											<tr><td style="padding-right: 10px;" valign="top" nowrap="nowrap" class="fieldphone">Дом. телефон: </td> <td>'.$rs->land_line.'</td></tr>
											</tr>
											</table>
											</div>
											</td>
											</tr>
											</table>
											</div>
											';
						}
				}//end while

			//prepares total list

			return $content;
		}//end listFriends()
		
	function getRequestList()
		{
			$this->load_settings();
			global $userId,$now;

			$friendsRequest	= $this->common->welcomeFriendsRequest($userId);
			$requestHead= 'У вас немає жодного вхідного запиту на дружбу';
			$requests	= '';
			$totRequest	= getTotRec("user_id","friends_list","friend_id='$userId' AND approved_status='no'");
			if($totRequest>0)
				{
					$res	= mysql_query("SELECT user_id AS friend_id FROM friends_list WHERE friend_id='$userId' AND approved_status='no'");
					if($res)
					while($rs = mysql_fetch_object($res))
						{
							$usrRs		= getRow("users","firstname, lastname","user_id='$rs->friend_id'");
							$username	= ''.$usrRs['firstname'].' '.$usrRs['lastname'].'';
							$acceptUrl	= base_url()."friends/confirm/".$rs->friend_id;
							$rejectUrl	= base_url()."friends/reject/".$rs->friend_id;
							$userAvatar	= $this->common->getAvatar($rs->friend_id);
							$profileUrl	= base_url()."user/profile/".$rs->friend_id;

							$requests	.='<tr>
											<td valign="top"> <div class="list2"><span><div><a href= '.$profileUrl.'><img src="'.$userAvatar.'" border="0"></a></div></span></div></td>
											<td width="100%"><table width="100%">
													<tr><td><a href= '.$profileUrl.'><strong>'.$username.'</strong></a> '.$this->common->offline($rs->friend_id, 'friends').'</td></tr>
													<tr><td>Чи бажаєте Ви додати користувача <a href='.$profileUrl.'>'.$username.'</a> до списку друзів?</td</tr>
													<tr><td>
													<div class="form-submit">
														<input type="button" value="Додати"    class="form-submit round-btn" onclick="window.location=\''.$acceptUrl.'\'">
														<input type="button" value="Відхилити" class="form-submit round-btn" onclick="window.location=\''.$rejectUrl.'\'">
													</div>
														</td>
													</tr>
												</table>
											</td>
										</tr>';
						}
				}
				else {
						$requests	= '<tr><td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="splborder2"><tr height="100"><td align="center"><b>'.$requestHead.'</b></td></tr></table></td></tr>';
				}
				
			$requests	= '
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td>
									<table width="100%" >
										'.$requests.'
									</table>
								</td>
								
							</tr></table>';
			return $requests;
		}//end getRequestList()

	function getOutRequestList()
		{
			$this->load_settings();
			global $userId,$now;

			$friendsRequest	= $this->common->welcomeFriendsRequest($userId);
			$requestHead= 'У вас немає жодного вихідного запиту на дружбу';
			$requests	= '';
			$totRequest	= getTotRec("friend_id","friends_list","user_id='$userId' AND approved_status='no'");
			if($totRequest>0)
				{
					$res	= mysql_query("SELECT friend_id FROM friends_list WHERE user_id='$userId' AND approved_status='no'");
					if($res)
					while($rs = mysql_fetch_object($res))
						{
							$usrRs		= getRow("users","firstname, lastname","user_id='$rs->friend_id'");
							$username	= ''.$usrRs['firstname'].' '.$usrRs['lastname'].'';
							$userAvatar	= $this->common->getAvatar($rs->friend_id);
							$profileUrl	= base_url()."user/profile/".$rs->friend_id;
							$rejectUrl	= base_url()."friends/rejectout/".$rs->friend_id;

							$requests	.='<tr>
											<td valign="top"> <div class="list2"><span><div><a href= '.$profileUrl.'><img src="'.$userAvatar.'" border="0"></a></div></span></div></td>
											<td><table width="100%">
													<tr><td width="100%"><a href= '.$profileUrl.'><strong>'.$username.'</strong></a> '.$this->common->offline($rs->friend_id, 'friends').'</td></tr>
													<tr><td class="outrequest">Користувач <a href='.$profileUrl.'>'.$username.'</a> повинен підтвердити що Ви його друг, після цього він додасть Вас до списку своїх друзів.</td</tr>
																										<tr><td>
													<div class="form-submit">
														<input type="button" value="Відхилити" class="form-submit round-btn" onclick="window.location=\''.$rejectUrl.'\'">
													</div>
														</td>
													</tr>
												</table>
											</td>
										</tr>';
						}
				}
				else {
						$requests	= '<tr><td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="splborder2"><tr height="100"><td align="center"><b>'.$requestHead.'</b></td></tr></table></td></tr>';
				}
				
			$requests	= '
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td>
									<table width="100%" cellpadding="4">
										'.$requests.'
									</table>
								</td>
								
							</tr></table>';
			return $requests;
		}//end getRequestList()
		
	function online($profileId)
		{
			$this->load_settings();
			$datas	= $this->common->authenticate();
			global $userId,$now;

			if(count($datas)<1)//if authentication failed
				{
					$datas	= $this->common->basicvars();
					$data	= $datas;
					$data['siteUrl']		= site_url();
					$data['center_login']	= true;
					$this->smartyextended->view('user/login',$data);
				}
			else//if authentication succeed
				{
					$data	= array();
					$data	= $datas;
					
					$data['count_friends_request']	= $this->common->countFriendRequest($userId);
					$data['count_new_msg']	= $this->common->countNewMsg($userId);
					$data['count_out_request']	= $this->common->countOutRequest($userId);

					$requestHead= 'Ніхто з ваших друзів не знаходиться зараз онлайн';
					
					$friendsList	= $this->common->onlineFriends($profileId);
					$content = '';
					
					if ($userId != $profileId && $profileId != '') {
					$curUsrRs	= getRow("users","firstname, lastname","user_id='$profileId'");
					$data['user_friend_online']	= '&rarr; '.$curUsrRs['firstname'].' '.$curUsrRs['lastname'];
					}
					
					if(!empty($friendsList))
						{
							for($i = 0; $i < count($friendsList); $i++) {
								$content	.=	$this->common->getSingleProfile($profileId,$friendsList[$i]);
							}
							
							$data['online_friends']	=	$content;
							$data['count_online']	=	count($this->common->onlineFriends($profileId));
						} 
					else 
						{
							$data['online_friends']		= '<tr><td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="splborder2"><tr height="100"><td align="center"><b>'.$requestHead.'</b></td></tr></table></td></tr>';
						}
					$data['online_now']		= true;
					$this->smartyextended->view('friends',$data);
				}
		}
		
	function load_settings()
		{
			global $userId,$now,$adminName,$adminEmail,$siteName,$siteTitle;
			$this->load->model('common');

			$userId		= $this->session->userdata('user_id');
			$now		= $this->config->item('now');

			$siteVars	= $this->common->getSiteVars();
			$adminName	= $siteVars['adminName'];
			$adminEmail	= $siteVars['adminEmail'];
			$siteName	= $siteVars['siteName'];
			$siteTitle	= $siteVars['siteTitle'];
		}//end load_settings()
}
?>
